<template>
  <!-- 一条文章单元格 -->
  <van-cell>
    <!-- 标题区域的插槽 -->
    <template #title>
      <div class="title-box">
        <!-- 标题 -->
        <span>{{ articleObj.title }}</span>
        <img
          v-if="articleObj.cover.type === 1"
          class="thumb"
          v-lazy="articleObj.cover.images[0]"
        />
      </div>
      <div class="thumb-box" v-if="articleObj.cover.type > 1">
        <!-- v-lazy图片懒加载 -->
        <img
          v-for="(item, index) in articleObj.cover.images"
          :key="index"
          class="thumb"
          v-lazy="item"
        />
      </div>
    </template>
    <!-- label 区域的插槽 -->
    <template #label>
      <div class="label-box">
        <div>
          <span>{{ articleObj.aut_name }}</span>
          <span>{{ articleObj.comm_count }} 评论</span>
          <span>{{ formatDate(articleObj.pubdate) }}</span>
        </div>
        <!-- 反馈按钮 -->
        <van-icon name="cross" @click.stop="crossFn(articleObj.art_id)" v-show="isShow" />
      </div>
    </template>
  </van-cell>
</template>

<script>
// 时间组件无需全局使用,所以在这里引入
import dayjs from 'dayjs'
import 'dayjs/locale/zh-cn' // import locale
import * as relativeTime from 'dayjs/plugin/relativeTime'

import { mapMutations } from 'vuex' // import plugin

dayjs.locale('zh-cn') // use locale
dayjs().format()
dayjs.extend(relativeTime)
export default {
  methods: {
    formatDate (data) {
      var a = dayjs()
      var b = dayjs(data)

      const c = a.to(b) // in 2 years
      return c
    },
    ...mapMutations(['changeArticleShowMutation', 'getArticleIdMutation']),
    // 反馈按钮部分
    crossFn (id_value) {
      // 点击开启弹框
      this.changeArticleShowMutation()
      this.getArticleIdMutation(id_value)
    }
  },
  props: {
    articleObj: Object,
    isShow: {
      type: Boolean,
      default: true
    }

  }
}
</script>

<style scoped lang="less">
/* 标题样式 */
.title-box {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}

/* label描述样式 */
.label-box {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

/* 文章信息span */
.label-box span {
  margin: 0 3px;
  &:first-child {
    margin-left: 0;
  }
}
.thumb {
  width: 113px;
  height: 70px;
  background-color: #f8f8f8;
  object-fit: cover;
}
.thumb-box {
  display: flex;
  justify-content: space-between;
}
</style>
